<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<script type="text/javascript">
<!--

jQuery.trimCommas = function(text) {
    return text == null ?
        "" :
        text.toString().replace(/^[\s,]+|[\s,]+$/g, "");
};

/**
 * 删除试卷确认 
 */
function delConfirm(paperID)
{
	var r=confirm("确认要删除试卷[" + paperID + "]吗");
	if (r==true)
	{
		window.location.href = "<%=basePath%>backend/backend.do?action=delPaper&paperID=" + paperID;
	}
	else
	{
	}
}

function addPaper()
{
	var paperName = $('input[name="paper_name"]').val();
	var paperDesc = $('input[name="paper_desc"]').val();
	var paperPrice = $('input[name="paper_price"]').val();
	paperName = $.trimCommas(paperName);
	paperDesc = $.trimCommas(paperDesc);
	paperPrice = $.trimCommas(paperPrice);
	if (paperName=="" || paperDesc=="" || paperPrice=="") {
		showError("请填写完整");
	}
	else {
		$("#add_form").submit();
	}
}

function showError(message) 
{
	$().Message({type:'error', time:2000,text:message, target:"#errorDiv", click:true});	
}

//-->
</script>
<div id="submenu">
	<div class="modules_left">
		<div class="module buttons">
			<a href="" class="dropdown_button"><small class="icon plus"></small><span>新建试卷</span></a>
			<div class="dropdown">
				<div class="arrow"></div>
				<div class="content">
					<form id='add_form' name='add_form' action="<%=basePath%>backend/backend.do?action=addPaper" method='POST'>
					
						<p>
							<div id="errorDiv">
							</div>
						</p>
						<p>
							<label for="simple_input">试题名称:</label>
							<input type="text" id="paper_name" name="paper_name" value="" class="text w_20" />
						</p>
						<p class="small"></p>
						<br />
						<p>
							<label for="simple_input">试题描述:</label>
							<input type="text" id="paper_desc" name="paper_desc" value="" class="text w_20" />
						</p>
						<p class="small"></p>
						<br />
						<p>
							<label for="simple_input">试题价格:</label>
							<input type="text" id="paper_price" name="paper_price" value="30" class="text w_20" />
						</p>
					</form>
					<a href="javascript:addPaper();" class="button green right"><small class="icon check"></small><span>Save</span></a>
					<a class="button red mr right close"><small class="icon cross"></small><span>Close</span></a>
					<div class="clear"></div>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="col w10 last">
	<div class="content">
		<table>
			<tr>
<!-- 				<th width="2%" class="checkbox"><input type="checkbox" name="checkbox" /></th> -->
				<th width="60%">试卷名称</th>
				<th width="10%">描述</th>
				<th width="10%">价格</th>
				<th width="10%">发布状态</th>
				<th width="10%">操作</th>
			</tr>
			<c:forEach var="paper" items="${papars}">
				<tr id="id_1">
<!-- 					<td class="checkbox"><input type="checkbox" name="checkbox" /></td> -->
					<td><a href="<%=basePath%>backend/backend.do?action=viewPaper&paperID=${paper.id}"><c:out value="${paper.paperTitle}" /></a></td>
					<td><c:out value="${paper.paperDesc}" /></td>
					<td><c:out value="${paper.paperPrice}" /></td>
					<td>
						<c:choose>
							<c:when test="${paper.paperStatus == '0'}">
								<img src="<%=basePath%>images/user-offline.png" />
							</c:when>
							<c:when test="${paper.paperStatus == '1'}">
								<img src="<%=basePath%>images/user-online.png" />
							</c:when>
						</c:choose>
					</td>
					<td>
						<c:choose>
							<c:when test="${paper.paperStatus == '0'}">
								<a href="<%=basePath%>backend/backend.do?action=publishPaper&paperID=${paper.id}&flag=1"><span>发布</span></a>
							</c:when>
							<c:when test="${paper.paperStatus == '1'}">
								<a href="<%=basePath%>backend/backend.do?action=publishPaper&paperID=${paper.id}&flag=0"><span>取消发布</span></a>
							</c:when>
						</c:choose>
						<a href="javascript:delConfirm('${paper.id}');"><span>删除</span></a>
					</td>
				</tr>
			</c:forEach>
		</table>
	</div>							
</div>
